#pragma once

#include "NFServerComm/NFServerCommon/NFIDescStore.h"
#include "NFServerComm/NFServerCommon/NFIDescTemplate.h"
#include "NFLogicCommon/NFDescStoreMacrosDefine.h"
#include "NFLogicCommon/NFDescStoreTypeDefines.h"
#include "E_ModuleControl.nanopb.h"
#ifndef MAX_MODULECONTROL_MODULECONTROL_NUM
#define MAX_MODULECONTROL_MODULECONTROL_NUM 30
#endif

struct ModuleControlWorldIdIdSubId
{
	ModuleControlWorldIdIdSubId()
	{
		if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode()) {
			CreateInit();
		}
		else {
			ResumeInit();
		}
	}
	int CreateInit()
	{
		world_id=0;
		id=0;
		sub_id=0;
		return 0;
	}
	int ResumeInit()
	{
		return 0;
	}
	int64_t world_id;
	int64_t id;
	int64_t sub_id;
	bool operator==(const ModuleControlWorldIdIdSubId& data) const
	{
		 return world_id== data.world_id && id== data.id && sub_id== data.sub_id;
	}
	std::string ToString() const
	{
		std::stringstream ios;
		ios << world_id;
		ios << ",";
		ios << id;
		ios << ",";
		ios << sub_id;
		return ios.str();
	}
};

namespace std
{
	template<>
	struct hash<ModuleControlWorldIdIdSubId>
	{
		size_t operator()(const ModuleControlWorldIdIdSubId& data) const
		{
			return NFHash::hash_combine(data.world_id,data.id,data.sub_id);
		}
	};
}


class ModuleControlDesc : public NFI_DESC_TEMPLATE_MACRO(ModuleControlDesc, E_ModuleControl, EOT_CONST_MODULECONTROL_MODULECONTROL_DESC_ID, MAX_MODULECONTROL_MODULECONTROL_NUM)
public:
	ModuleControlDesc();
	virtual ~ModuleControlDesc();
	int CreateInit();
	int ResumeInit();
public:
	int Load(NFResDb *pDB) override;
	int LoadDB(NFResDb *pDB) override;
	int CheckWhenAllDataLoaded() override;
	const E_ModuleControl* GetDescByWorldIdIdSubId(int64_t worldId, int64_t id, int64_t subId);
private:
	NFShmHashMap<ModuleControlWorldIdIdSubId, uint64_t, MAX_MODULECONTROL_MODULECONTROL_NUM> m_worldIdIdSubIdComIndexMap;
};
